package assembler

import (
	"github.com/gin-gonic/gin"
	"github.com/jinzhu/copier"
	"mine-info-server/domain/common-context/command"
	"mine-info-server/domain/common-context/query"
	"mine-info-server/interfaces/request"
)

/*
   @author:zhongyang
   @date:2023/4/11
   @description:通用-DTO和命令转换器
*/

type CommonAssembler struct {
}

func (c *CommonAssembler) ToCommandFromLoginRequest(req *request.LoginRequest) *command.LoginCommand {
	res := &command.LoginCommand{}
	copier.Copy(&res, req)
	return res
}

func (c *CommonAssembler) ToQueryFromGetMsgListRequest(context *gin.Context, req *request.GetMsgListRequest) *query.GetMsgListQuery {
	res := &query.GetMsgListQuery{}
	res.IsRead = 1
	if req.State == "history" {
		res.IsRead = 2
	}
	res.PageSize = req.PageSize
	res.Page = req.Page
	return res
}

func (c *CommonAssembler) ToCommandFromReadMsgRequest(req *request.GetById) *command.ReadMsgCommand {
	return &command.ReadMsgCommand{MsgId: req.ID}
}
